<template>
  <div>
    <el-dialog
      title=""
      :visible.sync="businessDialogVisible"
      width="38%"
      :before-close="handleClose"
    >
      <el-form
        :model="form"
        :inline="true"
        style="text-align: left"
        :rules="rules"
        ref="form"
        status-icon
      >
        <div>操作记录:</div>
        <el-input
          type="textarea"
          :rows="3"
          v-model="statusData.record"
          :disabled="true"
          class="changeOperation"
        ></el-input>
        <div>
          <p>
            <span>当前状态：</span>
            <span class="hk-state" v-if="statusData.replaceUnion == 0"
            >银联待解约 </span
            ><span class="hk-state" v-if="statusData.replaceUnion == 1" style="color: red"
          >银联已解约 </span
          ><span class="hk-state" v-if="statusData.replaceUnion == 2"
          >银联已签约 </span
          >
            <span class="hk-state" v-if="statusData.replaceYse == 0"
            >银盛待解约 </span
            ><span class="hk-state" v-if="statusData.replaceYse == 1" style="color: red"
          >银盛已解约 </span
          ><span class="hk-state" v-if="statusData.replaceYse == 2"
          >银盛已签约 </span
          >
          </p>
        </div>

        <!--        银联银盛都已签约成功--两个都可以解绑状态-->
        <div class="hkjb-btn" v-if="statusData.replaceUnion!=1 && statusData.replaceYse!=1">
          <el-popconfirm
            title="确定进行解绑么?"
            @onConfirm="unbundling('W100')"
            type="primary"
          >
            <el-button slot="reference" type="primary">银联解绑</el-button>
          </el-popconfirm>
          <el-popconfirm
            title="确定进行解绑么?"
            @onConfirm="unbundling('W200')"
            type="primary"
          >
            <el-button slot="reference" type="primary">银盛解绑</el-button>
          </el-popconfirm>
        </div>

        <!--        重新发起签约-->
        <div class="recontract" v-if="statusData.replaceUnion==1 || statusData.replaceYse==1">
          <el-form-item
            label="开户行:"
            label-width="80px"
            prop="bankDeposit"
          >
            <el-input
              v-model="form.bankDeposit"
              placeholder="请输入银行名称"
            ></el-input>
          </el-form-item>
          <el-form-item
            label="银行卡号:"
            label-width="80px"
            prop="bankCardNumber"
          >
            <el-input
              v-model="form.bankCardNumber"
              type="Number"
              placeholder="请输入银行卡号"
            ></el-input>
          </el-form-item>
          <el-form-item
            label="手机号码:"
            label-width="80px"
            prop="phoneNumber"
          >
            <el-input
              v-model="form.phoneNumber"
              type="Number"
              placeholder="请输入手机号码"
            ></el-input>
          </el-form-item>
          <div class="hkjb-btn">
            <el-popconfirm
              title="确定进行解绑么?"
              @onConfirm="unbundling('W100')"
              type="primary"
              v-if="statusData.replaceUnion!=1 && statusData.replaceYse==1"
            >
              <el-button slot="reference" type="primary">银联解绑</el-button>
            </el-popconfirm>
            <el-popconfirm
              title="确定发送链接?"
              @onConfirm="signing('form')"
              type="primary"
            >
              <el-button slot="reference" type="primary">发送链接</el-button>
            </el-popconfirm>
            <el-popconfirm
              title="确定进行解绑么?"
              @onConfirm="unbundling('W200')"
              type="primary"
              v-if="statusData.replaceUnion==1 && statusData.replaceYse!=1"
            >
              <el-button slot="reference" type="primary">银盛解绑</el-button>
            </el-popconfirm>

          </div>

        </div>

      </el-form>

    </el-dialog>
  </div>
</template>
<script>
import { getCode, getAlterSignInfo ,alterSignCancel,alterSignLink} from "../../assets/js/api";

export default {
  props: {
    indexTrue: {
      type: Boolean
    },
    statusData: {
      type: Object
    }
  },

  data() {
    var bankDeposit = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("银行名字不能为空"));
      } else {
        callback();
      }
    };
    var bankCardNumber = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("银行卡号不能为空"));
      } else {
        callback();
      }
    };
    var phoneNumber = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("手机号码不能为空"));
      } else {
        callback();
      }
    };
    return {
      form: {
        bankDeposit: "",
        bankCardNumber: "",
        phoneNumber: "",
      },
      rules: {
        bankDeposit: [{ validator: bankDeposit, trigger: "blur" }],
        bankCardNumber: [{ validator: bankCardNumber, trigger: "blur" }],
        phoneNumber: [{ validator: phoneNumber, trigger: "blur" }]
      }
    };
  },
  created() {
  },
  methods: {
    // 获取新的换卡信息!
    CardButton() {
      getAlterSignInfo(this.statusData.id).then((res) => {
        // this.statusData = res.data;
        this.$emit("statusData", res.data);
      });
    },
    // 解绑按钮!
    unbundling(channel) {
      //channel: W100   代表银联， W200 代表银盛
      let int = {};
      int.id = this.statusData.id;
      int.channel=channel;
      alterSignCancel(int).then((res) => {
        if (res.code == 200) {
          this.$message.success(res.message);
          this.CardButton();
        }
      });
    },
    //获取验证码!
    obtainCode() {
      if (this.form.mobile) {
        let int = {};
        int.cardNo = this.form.bankCardNumber;
        int.id = this.statusData.id;
        int.mobile = this.form.mobile;
        getCode(int).then((res) => {
          if (res.code == 200) {
            this.$message.success(res.message);
          } else {
            this.$message.error(res.message);
          }
        });
      } else {
        this.$message.error("请输入手机号码");
      }
    },

    //监听按钮!
    handleClose() {
      this.$emit("down", false);
      this.form.bankDeposit = "";
      this.form.bankCardNumber = "";
      this.form.phoneNumber = "";
      this.statusData.changeOperation = null;
    },
    //签约按钮!
    signing(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.form.id = this.statusData.id;
          alterSignLink(this.form).then((res) => {
            if (res.code == 200) {
              this.$message.success(res.message);
              this.CardButton();
              this.handleClose();
            } else {
              this.$message.error(res.message);
            }
          });
        }
      });
    }
  },
  computed: {
    businessDialogVisible: {
      get() {
        return this.indexTrue;
      },
      set() {
      }
    }
  },
  watch:{
    'statusData.bankDeposit':{
      handler(nv){
        this.form.bankDeposit=nv;
      },
      deep:true,
      immediate:true
    },
    'statusData.bankCardNumber':{
      handler(nv){
        this.form.bankCardNumber=nv;
      },
      deep:true,
      immediate:true
    },
    'statusData.phoneNumber':{
      handler(nv){
        this.form.phoneNumber=nv;
      },
      deep:true,
      immediate:true
    }
  }
};
</script>
<style lang="less" scoped>
/deep/ .inputClass {
  width: 100px;
  margin-right: 10px;
}

/deep/ .changeOperation {
  margin-bottom: 20px;

  .el-input__inner {
    height: 80px;
  }
}

.hk-state {
  font-size: 20px;
  font-weight: 600;
  display: inline-block;
  margin-right: 30px;
}

.hkjb-btn {
  margin: 20px 0;
  text-align: center;

}

/deep/ .hkjb-btn .el-button {
  margin: 0 30px;
  width: 150px;
  height: 50px;
}

.recontract {
  margin: 20px 0;
}
</style>